#coding:utf-8
import win32ui
import win32gui
import json
import os
MainScript = "D:\\script.dat"
def SaveingTheICON(path,str_save_id):
    large, small = win32gui.ExtractIconEx(path,0)
    print small
    win32gui.DestroyIcon(small[0])
    hdc = win32ui.CreateDCFromHandle( win32gui.GetDC(0) )
    hbmp = win32ui.CreateBitmap()
    hbmp.CreateCompatibleBitmap( hdc, 32, 32 )
    hdc = hdc.CreateCompatibleDC()
    hdc.SelectObject( hbmp )
    hdc.DrawIcon( (0,0), large[0] )
    hbmp.SaveBitmapFile( hdc, "img/"+str_save_id+".bmp" )
def AddToConfigFile(GamePath,GameName):

    dumps = json.loads(open(MainScript).read())
    dumps["all"] = dumps["all"] + 1
    dumps["program"][str(dumps["all"])] = {"name":GameName,"path":GamePath,"use":"yes"}
    file_object =open(MainScript,"w")
    file_object.write(json.dumps(dumps))
    file_object.close()
def LoadFromConfigFiles():
    if os.path.isfile(MainScript) == True:
        dumps = json.loads(open(MainScript).read())
        for i in dumps:
            print dumps[i]
        return dumps
LoadFromConfigFiles()
